package homework5.exp1;

import java.io.*;
import java.net.Socket;


/**
 * @author fengq
 */
public class LoginThread extends Thread {
    Socket socket = null;

    public LoginThread(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {

            //打开输入输出流
            InputStream is = socket.getInputStream();
            OutputStream os = socket.getOutputStream();
            //反序列化
            ObjectInputStream ois = new ObjectInputStream(is);
            //获取客户端信息，即从输入流读取信息
            User user = (User) ois.readObject();
            if (!(user == null)) {
                System.out.println("我是服务器，客户登录信息为：" + user.getLoginName() + "," + user.getPassword());
            }
            os.write("我爱你，你爱我，冰雪冰城甜蜜蜜".getBytes());
            is.close();
            ois.close();
            os.close();
            socket.close();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
